package com.lagou.controller;

import com.lagou.common.entity.Result;
import com.lagou.common.entity.StatusCode;
import com.lagou.pojo.Evaluation;
import com.lagou.service.EvaluationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/evaluation")
public class EvaluationController {
    @Autowired
    private EvaluationService evaluationService;

    /**
     * 查询所有
     */
    @RequestMapping(method = RequestMethod.GET)
    public Result findAll(){
        return new Result(true, StatusCode.OK,"查询成功",evaluationService.findAll());
    }

    /**
     * 根据id查询
     */
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public Result findById(@PathVariable String id){
        return new Result(true,StatusCode.OK,"根据id查询成功",evaluationService.findById(id));
    }

    /**
     * 添加
     */
    @RequestMapping(method = RequestMethod.POST)
    public Result add(@RequestBody Evaluation evaluation){
        evaluationService.add(evaluation);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/{id}",method = RequestMethod.PUT)
    public Result update(@RequestBody Evaluation evaluation,@PathVariable String id){
        evaluation.set_id(id);
        evaluationService.update(evaluation);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
    public Result delete(@PathVariable String id){
        evaluationService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /**
     * 根据父标签把对应的评论查找出来
     */
    public Result findByParentid(@PathVariable String parentid,@PathVariable int page,@PathVariable int size){
        return new Result(true,StatusCode.OK,"查找成功",evaluationService.findByParentid(parentid, page, size));
    }
}
